// pages/collectSite/collectSite.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    siteList:[
      {fish_place_name: "永顺园垂钓俱乐部", likes:true, fish_place_address: "北京市 通州 聊城西三路", fish_place_new_label:["小卖店","有饭","标鱼","活动","协议酒店"],fish_place_address:"北京市 通州 聊城西三路"},
      {fish_place_name: "永顺园垂钓俱乐部", likes:true, fish_place_address: "北京市 通州 聊城西三路", fish_place_new_label:["小卖店","有饭","标鱼","活动","协议酒店"],fish_place_address:"北京市 通州 聊城西三路"},
      {fish_place_name: "永顺园垂钓俱乐部", likes:true, fish_place_address: "北京市 通州 聊城西三路", fish_place_new_label:["小卖店","有饭","标鱼","活动","协议酒店"],fish_place_address:"北京市 通州 聊城西三路"},
      {fish_place_name: "永顺园垂钓俱乐部", likes:true, fish_place_address: "北京市 通州 聊城西三路", fish_place_new_label:["小卖店","有饭","标鱼","活动","协议酒店"],fish_place_address:"北京市 通州 聊城西三路"},
    ],
  },
  getList(){
    var data = {
      mobile_phone: wx.getStorageSync('mobile_phone'),
    }
    app.request('get', '/fishnews/getUserFavoritesPlaceList', data, res =>{
      this.setData({siteList: res.data.data.placeInfo})
    })
  },
  // 收藏钓场
  changeFavorite(e){
    var that = this
    let item = e.currentTarget.dataset.favorite
    console.log(item)
    let list = that.data.siteList
    list[e.currentTarget.dataset.index].is_favorite = item.is_favorite==1?0:1
    this.setData({siteList: list})

    app.request('POST', '/user/editUserFavorites?mobile_phone='+wx.getStorageSync('mobile_phone'), {
      "favorites_state": item.is_favorite==1?0:1,
      "fish_place_id": item.id
    }, res => {
      console.log(res)
    })
  },
  goto: function (e) {
    wx.navigateTo({
      url: e.currentTarget.dataset.url,
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})